package cn.it.infrastructure.domain.service.impl;

import cn.it.infrastructure.domain.service.IGoodsService;
import cn.it.infrastructure.mapper.IGoodsMapper;
import cn.it.infrastructure.mapper.IUserAndGoodsMapper;
import cn.it.infrastructure.po.TbGoods;
import cn.it.infrastructure.po.TbUserAndGoods;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Mzq
 * @description
 * @createTime 2024/7/4
 */
@Service
public class GoodsServiceImpl implements IGoodsService {

   private IGoodsMapper goodsMapper;

   private IUserAndGoodsMapper userAndGoodsMapper;

    public GoodsServiceImpl(IGoodsMapper goodsMapper, IUserAndGoodsMapper userAndGoodsMapper) {
        this.goodsMapper = goodsMapper;
        this.userAndGoodsMapper = userAndGoodsMapper;
    }


    @Override
   public TbGoods queryGoodsById(Long id) {
      return goodsMapper.selectByPrimaryKey(id);
   }

    @Override
    public List<TbGoods> queryRecommended() {
        // 查询评分好的商品id
        List<TbUserAndGoods> recommendedGoods = userAndGoodsMapper.selectByScore();

        List<TbGoods> goods = new ArrayList<>(recommendedGoods.size());
        for (TbUserAndGoods recommendedGood : recommendedGoods) {
            TbGoods goodsT = goodsMapper.selectByPrimaryKey(recommendedGood.getGoodsId());
            goods.add(goodsT);
        }

        return goods;
    }

    @Override
    public List<TbGoods> queryGoodsByContent(String content) {

        List<TbGoods> goods = goodsMapper.queryGoodsByContent(content);

        return goods;
    }
}
